//
//  AppDetailRestBridge.m
//  AboutUs
//
//  Created by Richa Pahwa on 2/10/13.
//  Copyright (c) 2013 Richa Pahwa. All rights reserved.
//

#import "AppDetailRestBridge.h"

@implementation AppDetailRestBridge

static AppDetailRestBridge* instance = nil;

+ (AppDetailRestBridge *) sharedInstance
{
    if (!instance) {
        instance = [[AppDetailRestBridge alloc] init];
    }
    return instance;
}

- (void)getAllApplicationsFromUrl:(NSString *)url withCompletionHandler: (RequestCompletionHandler) completionHandler
{
    NSOperationQueue *backgroundQueue = [[NSOperationQueue alloc] init];
    
    NSURLRequest *request = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:url]
                             cachePolicy:NSURLCacheStorageAllowedInMemoryOnly
                                              timeoutInterval:10];
    
    [NSURLConnection sendAsynchronousRequest:request
                                       queue:backgroundQueue
                           completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
                               NSString *result = [[NSString alloc] initWithData:data
                                                                        encoding:NSUTF8StringEncoding];
                               NSLog(@"%@",result);
                               if(completionHandler) {
                                   completionHandler(data, error);
                               }
                           }];
}

@end
